package hiho.ku._1097;

import java.util.Scanner;

public class Main {
	
	private static final int BIGINT = 999999;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[][] f = new int[n + 1][n + 1];
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				f[i][j] = in.nextInt();
		
		int[] d = new int[n + 1];
		for (int i = 0; i < n; i++)
			d[i] = BIGINT;
		
		boolean[] u = new boolean[n + 1];
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int pos = 0;
			for (int j = 1; j <= n; j++)
				if (!u[j] && d[j] < d[pos])
					pos = j;
			
			ans += d[pos];
			u[pos] = true;
			for (int j = 1; j <= n; j++)
				if (!u[j] && d[j] > f[pos][j])
					d[j] = f[pos][j];
		}
		System.out.println(ans);
	}

}
